package com.dcm360.report.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.dcm360.report.controller.BaseController;
import com.dcm360.report.controller.page.TableDataInfo;
import com.dcm360.report.system.domain.SysUserRole;
import com.dcm360.report.system.service.ISysUserRoleService;
import com.dcm360.report.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户和角色关联Controller
 * 
 * @author ruoyi
 * @date 2022-04-20
 */
@Api("用户和角色关联管理")
@RestController
@RequestMapping("/user-role")
public class SysUserRoleController extends BaseController {
    @Autowired
    private ISysUserRoleService sysUserRoleService;

    /**
     * 查询用户和角色关联列表
     */
    @ApiOperation("查询用户和角色关联列表")
    @GetMapping("/list")
    public TableDataInfo list(SysUserRole sysUserRole){
        startPage();
        List<SysUserRole> list = sysUserRoleService.selectSysUserRoleList(sysUserRole);
        return getDataTable(list);
    }


    /**
     * 获取用户和角色关联详细信息
     */
    @ApiOperation("获取用户和角色关联详细信息")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId){
        return AjaxResult.success(sysUserRoleService.selectSysUserRoleById(userId));
    }

    /**
     * 新增用户和角色关联
     */
    @ApiOperation("新增用户和角色关联")
    @PostMapping
    public AjaxResult add(@RequestBody SysUserRole sysUserRole){
        return toAjax(sysUserRoleService.insertSysUserRole(sysUserRole));
    }

    /**
     * 修改用户和角色关联
     */
    @ApiOperation("修改用户和角色关联")
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserRole sysUserRole){
        return toAjax(sysUserRoleService.updateSysUserRole(sysUserRole));
    }

    /**
     * 删除用户和角色关联
     */
    @ApiOperation("删除用户和角色关联")
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds){
        return toAjax(sysUserRoleService.deleteSysUserRoleByIds(userIds));
    }
}
